<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改密码</title>
<link rel="stylesheet"   href="/static/layui/css/layui.css" />
</head>
<body>
<div>
	<form class="layui-form layui-form-pane" >
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">原始密码:</label>
				<div class="layui-input-inline">
					<input class="layui-input" name="password" placeholder="原始密码" lay-verify="required" lay-reqText="请输入原始密码" />				
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">新密码:</label>
				<div class="layui-input-inline">
					<input class="layui-input" name="newPassword" placeholder="新密码" lay-verify="required" lay-reqText="请输入新密码" />				
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">确认密码:</label>
				<div class="layui-input-inline">
					<input class="layui-input" name="confirmPassword" placeholder="确认密码" lay-verify="required" lay-reqText="请确认密码" />				
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline layui-col-md-offset1">
				<button class="layui-btn" lay-submit  lay-filter="submitBtnFilter">确认</button>
				<button type="reset" class="layui-btn  layui-btn-primary" style="margin-left: 20px">重置</button>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="/static/layui/layui.js"> </script>
<script type="text/javascript" >

	layui.use(['form','layer','jquery'],function () {
		var form = layui.form ,
			layer = layui.layer,
			$ = layui.jquery;

	//	修改密码： 传给后台两个数据  旧密码 新密码
	//	确认密码在页面中进行校验，减少服务器的压力
		form.on('submit(submitBtnFilter)',function (obj) {  // obj 表单的数据
			// alert(obj.field.newPassword);
			//校验两次输入的密码是否相同
			if (obj.field.newPassword == obj.field.confirmPassword){
			//	  访问后端
				$.post("/user/user.do?service=updatePassword",obj.field ,function (rs) {
					var res = JSON.parse(rs); //转成json对象
					if (res.code == 200 ){
						layer.msg(res.msg+ "，3秒后跳转到登录页");
					//	 重新蹦到登录页面
						setTimeout(function () {
							window.parent.location.href = "/login.html"; //让父页面蹦到登录页去
						},3000) ; // 延时3秒之后跳转页面

					}else{
						layer.msg(res.msg);
					}
				})
			}else {
				layer.msg("两次输入的密码不一致！");
			}
			return false; // 防止表单提交
		})
	})

</script>
</body>
</html>